package com.zlq.cn.controller.sign.ai;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.volcengine.service.visual.model.request.*;
import com.volcengine.service.visual.model.response.*;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.bootstrap.SignApiBootstrap;
import com.zlq.cn.config.Config;
import com.zlq.cn.dto.param.TencentAiParam;
import com.zlq.cn.dto.visual.request.AllAgeGenerationRequest;
import com.zlq.cn.dto.visual.request.DollyZoomRequest;
import com.zlq.cn.dto.visual.response.AllAgeGenerationResponse;
import com.zlq.cn.dto.visual.response.DollyZoomResponse;
import com.zlq.cn.entity.FanyiUser;
import com.zlq.cn.entity.SuggestRecord;
import com.zlq.cn.entity.TencentAi;
import com.zlq.cn.service.un.FanyiUserService;
import com.zlq.cn.service.un.SuggestRecordService;
import com.zlq.cn.service.ai.AiCommonService;
import com.zlq.cn.service.ai.VolcengineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhoucl
 * @since 2022-03-05
 */
@Api(tags = "火山引擎AI")
@Validated
@RestController
@RequestMapping("/volcengine/ai")
public class VolcengineAiController {
    @Resource
    private FanyiUserService fanyiUserService;

    @Resource
    private VolcengineService volcengineService;

    @Resource
    private SuggestRecordService suggestRecordService;

    @Resource
    private AiCommonService aiCommonService;

    @ApiOperation("图片流动-imageFlow")
    @PostMapping("/image/flow")
    public SignApiResult<VisualImageFlowResponse> imageFlow(@RequestBody VisualImageFlowRequest param) {
        return SignApiResult.resultSuccess(volcengineService.imageFlow(param));
    }

    @ApiOperation("图片评分-imageScore")
    @PostMapping("/image/score")
    public SignApiResult<VisualImageScoreResponse> imageScore(@RequestBody VisualImageScoreRequest param) {
        return SignApiResult.resultSuccess(volcengineService.imageScore(param));
    }

    @ApiOperation("图片配文-poemMaterial")
    @PostMapping("/poem/material")
    public SignApiResult<VisualPoemMaterialResponse> poemMaterial(@RequestBody VisualPoemMaterialRequest param) {
        return SignApiResult.resultSuccess(volcengineService.poemMaterial(param));
    }

    @ApiOperation("人像融合-faceSwap")
    @PostMapping("/face/swap")
    public SignApiResult<VisualFaceSwapResponse> faceSwap(@RequestBody VisualFaceSwapRequest param) {
        return SignApiResult.resultSuccess(volcengineService.faceSwap(param));
    }

    @ApiOperation("人像漫画风-jpCartoon")
    @PostMapping("/jp/cartoon")
    public SignApiResult<VisualJPCartoonResponse> jpCartoon(@RequestBody VisualJPCartoonRequest param) {
        return SignApiResult.resultSuccess(volcengineService.jpCartoon(param));
    }

    @ApiOperation("人像抠图-humanSegment")
    @PostMapping("/human/segment")
    public SignApiResult<VisualHumanSegmentResponse> humanSegment(@RequestBody VisualHumanSegmentRequest param) {
        return SignApiResult.resultSuccess(volcengineService.humanSegment(param));
    }

    @ApiOperation("闭眼转睁眼-eyeClose2Open")
    @PostMapping("/eye/close/to/open")
    public SignApiResult<VisualEyeClose2OpenResponse> eyeClose2Open(@RequestBody VisualEyeClose2OpenRequest param) {
        return SignApiResult.resultSuccess(volcengineService.eyeClose2Open(param));
    }

    @ApiOperation("表情编辑-emotionEdit")
    @PostMapping("/emotion/edit-")
    public SignApiResult<VisualEmoticonEditResponse> emotionEdit(@RequestBody VisualEmoticonEditRequest param) {
        return SignApiResult.resultSuccess(volcengineService.emotionEdit(param));
    }

    @ApiOperation("人像畸变矫正-distortionFree")
    @PostMapping("/distortion/free")
    public SignApiResult<VisualDistortionFreeResponse> distortionFree(@RequestBody VisualDistortionFreeRequest param) {
        return SignApiResult.resultSuccess(volcengineService.distortionFree(param));
    }

    @ApiOperation("图片拉伸修复-stretchRecovery")
    @PostMapping("/stretch/recovery")
    public SignApiResult<VisualStretchRecoveryResponse> stretchRecovery(@RequestBody VisualStretchRecoveryRequest param) {
        return SignApiResult.resultSuccess(volcengineService.stretchRecovery(param));
    }

    @ApiOperation("图像增强-enhancePhoto")
    @PostMapping("/enhance/photo")
    public SignApiResult<VisualEnhancePhotoResponse> enhancePhoto(@RequestBody VisualEnhancePhotoRequest param) {
        return SignApiResult.resultSuccess(volcengineService.enhancePhoto(param));
    }

    @ApiOperation("老照片修复-convertPhoto")
    @PostMapping("/convert/photo")
    public SignApiResult<VisualConvertPhotoResponse> convertPhoto(@RequestBody VisualConvertPhotoRequest param) {
        return SignApiResult.resultSuccess(volcengineService.convertPhoto(param));
    }

    @ApiOperation("人像特效-potraitEffect")
    @PostMapping("/potrait/effect")
    public SignApiResult<VisualPotraitEffectResponse> potraitEffect(@RequestBody VisualPotraitEffectRequest param) {
        return SignApiResult.resultSuccess(volcengineService.potraitEffect(param));
    }

    @ApiOperation("希区柯克特效-dollyZoom")
    @PostMapping("/dolly/zoom")
    public SignApiResult<DollyZoomResponse> dollyZoom(@RequestBody DollyZoomRequest param) {
        return SignApiResult.resultSuccess(volcengineService.dollyZoom(param));
    }

    @ApiOperation("希区柯克特效V2-img2Video3D")
    @PostMapping("/img2/video3d")
    public SignApiResult<VisualImg2Video3DResponse> img2Video3D(@RequestBody VisualImg2Video3DRequest param) {
        return SignApiResult.resultSuccess(volcengineService.img2Video3D(param));
    }

    @ApiOperation("人像年龄变换-allAgeGeneration")
    @PostMapping("/all/age/generation")
    public SignApiResult<AllAgeGenerationResponse> allAgeGeneration(@RequestBody AllAgeGenerationRequest param) {
        return SignApiResult.resultSuccess(volcengineService.allAgeGeneration(param));
    }

    @ApiOperation("图片列表")
    @PostMapping("/image/page")
    public SignApiResult<Page<TencentAi>> imagePage(@RequestBody TencentAiParam param) {
        param.setProject(Config.PROJECT_VOLCENGINE_AI);
        return SignApiResult.resultSuccess(aiCommonService.imagePage(param.getPage(), param));
    }

    @ApiOperation("删除AI图片查询")
    @PostMapping("/delete/image")
    public SignApiResult<Boolean> deleteImage(@RequestBody TencentAi param) {
        param.setProject(Config.PROJECT_VOLCENGINE_AI);
        return SignApiResult.resultSuccess(aiCommonService.deleteImage(param));
    }

    @ApiOperation("获取服务器时间")
    @GetMapping("/sys/time")
    public SignApiResult<Long> sysTime() {
        return SignApiResult.resultSuccess(System.currentTimeMillis());
    }

    @ApiOperation("用户登录/注册")
    @PostMapping("/login")
    public SignApiResult<FanyiUser> login(@RequestBody Object o) {
        FanyiUser fanyiUser = fanyiUserService.login(Config.PROJECT_VOLCENGINE_AI);
//        fanyiUser.setOpen(open);
        return SignApiResult.resultSuccess(fanyiUser);
    }

    @ApiOperation("反馈")
    @PostMapping("/suggest/add")
    public SignApiResult<String> suggestRecord(@RequestBody SuggestRecord suggestRecord) {
        suggestRecord.setProject(Config.PROJECT_VOLCENGINE_AI);
        suggestRecord.setIsreply(0);
        suggestRecord.setType(SignApiBootstrap.get().getImei());
        suggestRecord.setSubmitdate(LocalDateTime.now());
        suggestRecordService.save(suggestRecord);
        return SignApiResult.resultSuccess("反馈成功");
    }
}

